﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib.Accounts.Bus;
using System.Data;

namespace Ewts.Storage
{
    public partial class WaitCollecList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["UserInfo"] != null)
                {
                    User curUser = new User();
                    curUser = (User)Session["UserInfo"];

                    //归属地
                    ListItem item = new ListItem();
                    item.Text = "--请选择--";
                    item.Value = "";
                    DataLib.BLL.City bllLib = new DataLib.BLL.City();
                    dropBelong.DataSource = bllLib.GetList("flag1= '02'");
                    dropBelong.DataTextField = "cityname";
                    dropBelong.DataValueField = "citycode";
                    dropBelong.DataBind();
                    dropBelong.Items.Insert(0, item);



                    if (curUser.UserType == "AA")
                    {
                        dropBelong.Enabled = false;
                        dropBelong.SelectedItem.Text = curUser.CompanyCity;
                        bindData(dropBelong.SelectedItem.Text);
                    }
                    else
                    {
                        bindData("");
                    }
                }
                else
                {
                    Response.Redirect("/accounts/login.aspx");
                }
                
            }
        }

        /// <summary>
        /// 绑定待派车的信息
        /// </summary>
        /// <param name="city"></param>
        protected void bindData(string city)
        {
            //收货派车
            string collagewhere = " c.status=1 and c.islocal=1 ";
            //移库派车
            string outwhere = " totalweight<>0 and status=2 ";
            if (city != "")
            {
                collagewhere += " and l.rubbisharea ='" + city + "'";
                outwhere += " and OutDepart='" + city + "'";
            }

            DataTable dt = new DataLib.BLL.CJOItem().GetList_PROCJO("",city,1,1);
            rept.DataSource = dt;
            rept.DataBind();
 
            DataTable outdt = new DataLib.BLL.OutStorage().GetList(outwhere).Tables[0];
            reptOutStorage.DataSource = outdt;
            reptOutStorage.DataBind();
        }

 

        /// <summary>
        /// 获取字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string GetSubString(string str, int len)
        {
            string strreturn = "";
            if (str.Length > len)
            {
                strreturn = str.Substring(0, len) + "...";
            }
            else
            {
                strreturn = str;
            }
            return strreturn;
        }

        protected void dropBelong_SelectedIndexChanged(object sender, EventArgs e)
        {
            bindData(dropBelong.SelectedItem.Text);
        }

        /// 20130325 梁玲
        /// 取得业务员姓名
        protected string GetName(string saleman)
        {
            return new User(saleman).TrueName;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="flag">标识为1取名称，否则 取编码</param>
        /// <returns></returns>
        public string GetCumByOutID(object id, int flag)
        {
            int outid = int.Parse(id.ToString());
            DataLib.Model.OutStorage model = new DataLib.BLL.OutStorage().GetModel(outid);
            string cumname = "";

            if (model.VLoadNum.Substring(0, 2) == "86") 
            {
                DataLib.Model.LoadNum lmodel = new DataLib.BLL.LoadNum().GetLoadID(model.VLoadNum);
                cumname = lmodel.cumname;
            }
            else if (model.inDepart == model.belogarea )
            {
                cumname = model.graphicCity + "库";
            }
            else if (model.inDepart != model.belogarea)
            {
                cumname = model.belogarea + "伟翔";
            }
            return cumname;
        }

    }
}